package cn.patient.pp.module.patients.controller.admin.vo;

import cn.patient.pp.framework.common.pojo.PageParam;
import cn.patient.pp.framework.security.core.LoginUser;
import cn.patient.pp.framework.security.core.util.SecurityFrameworkUtils;
import cn.patient.pp.module.system.dal.dataobject.user.AdminUserDO;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

@Data
public class BigScreenReqVO {

    @NotNull(message = "时间类型不能为空")
    private String timeType;

    private Long deptId;

    private List<Long> deptIds;

    private String startTime;

    private String endTime;


    private Long userId;

    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");

    public void setTimeType(String timeType) {
        this.timeType = timeType;

        // 如果前端已经传了 startTime 和 endTime，就不自动设置
        if (this.startTime != null && this.endTime != null) {
            return;
        }

        LocalDate now = LocalDate.now();
        LocalDate start;

        switch (timeType) {
            case "01": // 最近7天
                start = now.minusDays(7);
                break;
            case "02": // 最近6个月
                start = now.minusMonths(6);
                break;
            case "03": // 最近12个月
                start = now.minusMonths(12);
                break;
            default:
                return; // 无效的 timeType，不处理
        }

        this.startTime = start.format(FORMATTER);
        this.endTime = now.format(FORMATTER);
    }

}
